﻿<UserControl x:Class="Scrabble.Views.PlayerView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:uc="clr-namespace:Microsoft.Windows.Controls;assembly=U2UConsult.RichHtmlTextBlock"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:Controls="clr-namespace:Scrabble.Controls" mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Themes/DataGridStyles.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

    <DockPanel>
        <DockPanel.Resources>
            <uc:HtmlFormatter x:Key="HtmlFormatter" />
            <Controls:NotationToMarkupConverter x:Key="NotationConverter" BoldColor="DarkOrange" />

            <DataTemplate x:Key="WordCell">
                <Grid x:Name="WordHost">
                    <uc:RichTextBox Text="{Binding Description, Converter={StaticResource NotationConverter}, Mode=OneWay}" TextFormatter="{StaticResource HtmlFormatter}" 
                    Background="{x:Null}" BorderThickness="0" Width="{Binding Path=ActualWidth, ElementName=WordHost, Mode=OneWay}" />
                </Grid>
            </DataTemplate>

            <Style x:Key="RightAlignCellStyle" BasedOn="{StaticResource CellWithoutSelection}" TargetType="DataGridCell">
                <Setter Property="TextBlock.TextAlignment" Value="Right"/>
            </Style>
        </DockPanel.Resources>

        <DataGrid x:Name="EventLog" ItemsSource="{Binding EventLog}" FrozenColumnCount="1" Style="{StaticResource DataGridStyle}" CellStyle="{StaticResource CellWithoutSelection}" HeadersVisibility="Column" >
            <DataGrid.RowStyle>
                <Style TargetType="DataGridRow">
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Background" Value="LemonChiffon" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.RowStyle>

            <DataGrid.Columns>
                <DataGridTemplateColumn Header="Word" MinWidth="100" CellTemplate="{StaticResource WordCell}" />
                <DataGridTextColumn Header="Location" MinWidth="60" Binding="{Binding PlayVector}" />
                <DataGridTextColumn Header="Score" MinWidth="60" Binding="{Binding Score}" HeaderStyle="{StaticResource CenterAlignHeaderStyle}" CellStyle="{StaticResource RightAlignCellStyle}" />
                <DataGridTextColumn Header="Time" MinWidth="65" Binding="{Binding DurationOfPlay, StringFormat=mm\\:ss}" HeaderStyle="{StaticResource CenterAlignHeaderStyle}" CellStyle="{StaticResource RightAlignCellStyle}" />
            </DataGrid.Columns>
        </DataGrid>
    </DockPanel>
</UserControl>
